clear

*Note: first change working directory replication package folder

run "scripts/programs/program_data.do"
run "scripts/programs/program_regs.do"
run "scripts/programs/program_regtable.do"


/*********************************************************************************/
*Set program parameters
local radius = 20
local angle = 15
local length = 1
/**********************************************************************************/

data anypop pop anyhu hu hudens lnpop popdens inc_pcincome inc_totinc inc_huxpcinc inc_pct_poverty ///
		count_res count_mobile count_sfr ///
		any_res val_res val_mobile val_sfr ///
		avgval_res avgval_mobile avgval_sfr ///
		race_pct_whitenh race_pct_amind ///
		race_pct_black race_pct_hisp tenure_pct_rent tri ///
		lnt lnint t1 t2 t3 t4 t5 t6 tmissing roadpcttot majorroad tritot habpolytot hablinetot wsimptot ///
		campground wilderness wind_diff ///
		using "data/`radius'-by-`length'km_`angle'deg/data_centroid.dta", ///
		maxlags(0) maxleads(0) burnt(centroid) tcuts(1,2,3,4,5,8)

merge m:1 firenum using ///
	"data/`radius'-by-`length'km_`angle'deg/sample_census.dta", ///
	nogen
collapse (max) duration sample, by(ignitionid directionnum)
keep if sample == 1

egen dirid = group(ignitionid directionnum)
distinct dirid
local nfiredir =`r(ndistinct)'
local nfiredirc: di %9.0gc `r(ndistinct)'
di "`nfiredirc'"
distinct ignitionid
local nfire =`r(ndistinct)'
local nfirec: di %9.0gc `nfire'
local numfire = "`nfirec'"
di "`numfire'"

histogram duration, discrete start(0) ///
	fcolor(dknavy) fintensity(75) lcolor(white) gap(1) ///
	xtitle(`"Spread distance from ignition point (km)"') ///
	graphregion(fcolor(white)) ///
	text(0.15 15 `"Distribution of fire duration"' `"over`numfire' fires and`nfiredirc'"' ///
		`"directions of spread"', justification(left) size(small*1.05))
	*title(`"Distribution of fire spread distances"') ///
*	note(`"Note: To measure fire spread distances, the landscape was into $radius kilometers directions of  "' ///
*	`"spread of $angle degrees. Each spread direction was then divided into intervals of $length km."', size(small))

graph export "Results/durationhist.eps", replace
graph export "Results/durationhist.pdf", replace
graph export "Results/durationhist.png", replace
